package com.zzsy.shoppingpro.home.acitivty;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;

import com.zzsy.shoppingpro.R;
import com.zzsy.shoppingpro.app.Config;
import com.zzsy.shoppingpro.base.BaseActivity;
import com.zzsy.shoppingpro.commentactivity.GoodsInfoActivity;
import com.zzsy.shoppingpro.home.adapter.SeckillGridViewAdapter;
import com.zzsy.shoppingpro.home.bean.GoodsBean;
import com.zzsy.shoppingpro.home.bean.HomeBean;

import java.util.ArrayList;

public class SeckillDeticActivity extends BaseActivity {

    private GridView gvSeckill;
    private TextView tvTitle;
    private ArrayList<HomeBean.ResultBean.SeckillInfoBean.ListBean> listBeans;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seckill_detic);
        listBeans = new ArrayList<>();
        initData();
        initUI();
    }

/**
 * 初始化控件
 * */
    private void initUI() {
        tvTitle = findViewById(R.id.title);
        tvTitle.setText("秒杀列表");

        gvSeckill = findViewById(R.id.gv_seckill);
        SeckillGridViewAdapter seckillGridViewAdapter = new SeckillGridViewAdapter(SeckillDeticActivity.this,listBeans);
        gvSeckill.setAdapter(seckillGridViewAdapter);
        gvSeckill.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String cover_price = listBeans.get(position).getCover_price();
                String name = listBeans.get(position).getName();
                String figure = listBeans.get(position).getFigure();
                String product_id = listBeans.get(position).getProduct_id();
                GoodsBean goodsBean = new GoodsBean(name, cover_price, figure, product_id);

                Intent intent = new Intent(SeckillDeticActivity.this, GoodsInfoActivity.class);
                intent.putExtra(Config.GOODS_BEAN, goodsBean);
                startActivity(intent);
            }
        });

    }

    /**
     * 初始化数据
     * */
    private void initData() {
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        listBeans = (ArrayList<HomeBean.ResultBean.SeckillInfoBean.ListBean>) bundle.getSerializable("seckill");
    }

}
